package com.music.music.service.impl;

import java.util.List;

import com.music.music.domain.Singer;
import com.music.music.mapper.SingerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.music.music.mapper.MusicSingerMapper;
import com.music.music.domain.MusicSinger;
import com.music.music.service.MusicSingerService;

import javax.annotation.Resource;

/**
 * 音乐与歌手关联表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@Service
public class MusicSingerServiceImpl implements MusicSingerService 
{
    @Resource
    private MusicSingerMapper musicSingerMapper;
    @Resource
    private SingerMapper singerMapper;
    /**
     * 查询音乐与歌手关联表
     * 
     * @param musicId 音乐与歌手关联表主键
     * @return 音乐与歌手关联表
     */
    @Override
    public MusicSinger selectMusicSingerByMusicId(Long musicId)
    {
        return musicSingerMapper.selectMusicSingerByMusicId(musicId);
    }

    /**
     * 查询音乐与歌手关联表列表
     * 
     * @param musicSinger 音乐与歌手关联表
     * @return 音乐与歌手关联表
     */
    @Override
    public List<MusicSinger> selectMusicSingerList(MusicSinger musicSinger)
    {
        return musicSingerMapper.selectMusicSingerList(musicSinger);
    }

    /**
     * 新增音乐与歌手关联表
     * 
     * @param musicSinger 音乐与歌手关联表
     * @return 结果
     */
    @Override
    public int insertMusicSinger(MusicSinger musicSinger)
    {
        return musicSingerMapper.insertMusicSinger(musicSinger);
    }

    /**
     * 修改音乐与歌手关联表
     * 
     * @param musicSinger 音乐与歌手关联表
     * @return 结果
     */
    @Override
    public int updateMusicSinger(MusicSinger musicSinger)
    {
        return musicSingerMapper.updateMusicSinger(musicSinger);
    }

    /**
     * 批量删除音乐与歌手关联表
     * 
     * @param musicIds 需要删除的音乐与歌手关联表主键
     * @return 结果
     */
    @Override
    public int deleteMusicSingerByMusicIds(Long[] musicIds)
    {
        return musicSingerMapper.deleteMusicSingerByMusicIds(musicIds);
    }

    /**
     * 删除音乐与歌手关联表信息
     * 
     * @param musicId 音乐与歌手关联表主键
     * @return 结果
     */
    @Override
    public int deleteMusicSingerByMusicId(Long musicId)
    {
        return musicSingerMapper.deleteMusicSingerByMusicId(musicId);
    }

    @Override
    public String findSingerNameById(Long musicId) {
        List<Long> singIdList = musicSingerMapper.selectSingerNameById(musicId);
        StringBuilder singerNameStr = new StringBuilder();
        for (int i = 0; i < singIdList.size(); i++) {
            Singer singer = singerMapper.selectSingerBySingerId(singIdList.get(i));

            if(i==singIdList.size()-1){
                singerNameStr.append(singer.getSingerName());
            }else {
                singerNameStr.append(singer.getSingerName()).append("/");
            }
        }
        return singerNameStr.toString();
    }

}
